package com.mitdy.sg.data.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mitdy.sg.common.bean.Pagination;
import com.mitdy.sg.data.mapper.TeamMapper;
import com.mitdy.sg.data.vo.TeamVO;

@Service
public class TeamService {

	@Autowired
	private TeamMapper teamMapper;

	public PageInfo<TeamVO> getTeamPageInfo(TeamVO team, Pagination pagination) {
		Page<TeamVO> page = PageHelper.startPage(pagination.getPage(), pagination.getRows());
		teamMapper.getPageInfo(team);
		PageInfo<TeamVO> pageInfo = new PageInfo<TeamVO>(page);
		return pageInfo;
	}
	
	public TeamVO getTeamById(Long teamId) {
		return teamMapper.getTeamById(teamId);
	}

	@Transactional
	public TeamVO addTeam(TeamVO team) {
		teamMapper.insert(team);
		return team;
	}

    @Transactional
	public TeamVO updateTeam(TeamVO team) {
		teamMapper.updateByPrimaryKeySelective(team);
		return team;
	}

	@Transactional
	public void deleteTeamById(Long teamId) {
		teamMapper.deleteByPrimaryKey(teamId);
	}

    public TeamVO getTeamByName(String teamName) {
        return teamMapper.getTeamByName(teamName);
    }

}